﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LJF.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace LJF.ManageSYS.Controllers
{
    /// <summary>
    /// 控制器基类
    /// </summary>
    public class BaseController : ControllerBase
    {
        /// <summary>
        /// 成功返回数据
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public ResponseData Success(object obj)
        {
            ResponseData res = new ResponseData()
            {
                Data = obj
            };
            return res;
        }

        /// <summary>
        /// 成功返回数据，添加总数
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public ResponseData Success(object obj,int count)
        {
            ResponseData res = new ResponseData()
            {
                Count = count,
                Data = obj                
            };
            return res;
        }

        /// <summary>
        /// 操作成功返回提示信息
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public ResponseData Success(string info="操作成功")
        {
            ResponseData res = new ResponseData()
            {
                Msg = info
            };
            return res;
        }

        /// <summary>
        /// 操作成功返回提示信息和数据
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public ResponseData Success(object data,string info = "操作成功")
        {
            ResponseData res = new ResponseData()
            {
                Msg = info,
                Data=data
            };
            return res;
        }

        /// <summary>
        /// 请求失败
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public ResponseData Fail(string info = "请求失败")
        {
            ResponseData res = new ResponseData()
            {
                Code=1,
                Msg=info
            };
            return res;
        }

        /// <summary>
        /// 请求失败，返回相关数据
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public ResponseData Fail(object data,string info = "请求失败")
        {
            ResponseData res = new ResponseData()
            {
                Code = 1,
                Msg = info,
                Data=data
            };
            return res;
        }
    }
}